//
//  YTWithdrawAccountCell.m
//  YiTuDriverClient
//
//  Created by 石少庸 on 2017/5/26.
//  Copyright © 2017年 Yitu. All rights reserved.
//

#import "YTWithdrawAccountCell.h"
#import "YTWithdrawAccountModel.h"

@interface YTWithdrawAccountCell ()
@property (weak, nonatomic) IBOutlet UIImageView *bgImage;
@property (weak, nonatomic) IBOutlet UILabel *nameText;
@property (weak, nonatomic) IBOutlet UILabel *accountText;
@property (weak, nonatomic) IBOutlet UILabel *typeText;
@property (strong, nonatomic) UIButton *deleteBtn;
@end

@implementation YTWithdrawAccountCell

- (void)setModel:(YTWithdrawAccountModel *)model {
    _model = model;
    _bgImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"profile_withdraw%@", model.type]];
    _typeText.text = model.typeStr;
    
    // 账户名
    NSString *firstChar = [model.name substringToIndex:1];
    NSString *lastChar = [model.name substringWithRange:NSMakeRange(model.name.length - 1, 1)];
    if (model.name.length == 2) {
         _nameText.text = [NSString stringWithFormat:@"*%@", lastChar];
    }
    
    if (model.name.length > 2) {
        NSString *lastChar = [model.name substringWithRange:NSMakeRange(model.name.length - 1, 1)];
        _nameText.text = [NSString stringWithFormat:@"%@*%@", firstChar, lastChar];
    }
    
    // 账号,除了银行账号需要做隐藏,其他都不需要
    if ([model.type isEqualToString:@"3"]) {
        NSString *back = [model.number substringWithRange:NSMakeRange(model.number.length - 4, 4)];
        _accountText.text = [NSString stringWithFormat:@"**** **** **** %@", back];
    } else {
        _accountText.text = model.number;
    }
}

- (void)layoutSubviews {
    [super layoutSubviews];
    for (UIView *subView in self.subviews){
        if([subView isKindOfClass:NSClassFromString(@"UITableViewCellDeleteConfirmationView")]) {
            CGRect cRect = subView.frame;
            cRect.size.height = self.contentView.frame.size.height - 20;
            cRect.origin.y = 10;
            subView.frame = cRect;
            break;
        }
    }
}

@end
